// 订单利润分析
<template>
  <div class="tenantMenu_main main_container">
    <div class="main_header">
      <div class="padding_container">
        <div class="left"><Breadcrumb /></div>
        <div class="right">
          <HeaderOperation :parent="this" />
        </div>
      </div>
    </div>
    <div v-loading="loading" class="main_main">
      <SearchBar :parent="this" />
      <div ref="table_container" class="table_container">
        <el-table
          ref="table"
          :data="tableData"
          :height="tableHeight"
          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
          row-key="uuid"
          show-summary
          stripe
          border
          :summary-method="getSummaries"
          :cell-style="cellStyle"
          :cell-class-name="cellClassName"
          @cell-click="cellClick"
          @sort-change="(column)=>{sortChange(column, this)}"
          @selection-change="(val)=>{selectionChange(val, this)}"
        >
          <el-table-column type="selection" align="center" width="70" />
          <Column
            v-for="(column,index) in tableColumns"
            :key="index"
            :prop="column.prop"
            :is-show="column.isShow"
            :label="column.label"
            :sortable="column.sortable"
            :width="column.width"
            :min-width="column.minWidth"
            :fixed="column.fixed"
            :align="column.align"
          />
        </el-table>
      </div>
    </div>
    <div class="main_bottom">
      <pagination
        :total="total"
        :page.sync="pageData.pageNum"
        :limit.sync="pageData.pageSize"
        :selected-num="selectionsAll.length"
        @pagination="getList"
      />
    </div>

  </div>
</template>

<script>
import { list, exporOrderProfittList } from '@/api/receivableAndPayable/receivableAndPayableManage/orderProfitAnalyse'
import { getInfo } from '@/api/saleManage/saleOrder'
import { getInfo as productionInfo } from '@/api/purchaseManage/purchaseOrder'
import { getInfo as getOutsourceOrderInfo } from '@/api/outsourceManage/outsourceOrder'
import { getInfo as planProductionInfo } from '@/api/planManagement/planProductionOrder'
import { getInfo as AdditionalInfo } from '@/api/receivableAndPayable/receivableAndPayableManage/additionalPaymentOrder'
import ShowPurchaseDetail from '@/views/purchaseManage/purchaseOrder/showPurchaseOrder'
import showDetailSale from '@/views/saleManage/saleOrder/showDetail'
import outsourceShowDetail from '@/views/outsourceManage/outsourceOrder/showOutsourceOrder'
import ShowPlanProducionDetail from '@/views/planManagement/planProductionOrder/ShowDetailTitle'
import ShowAdditionalDetail from '@/views/receivableAndPayable/additionalPaymentOrder/showAdditionalPaymentOrder' // 查看页面
export default {
  name: 'Index',
  data() {
    return {
      loading: true,
      pageId: '订单利润分析表', // 页面唯一标识
      pageExportId: '订单利润分析导出',
      pageData: {
        pageNum: 1,
        pageSize: 20,
        orderByColumn: 'saleOrderCode',
        isAsc: 'desc'
      },
      clearable: false, // 日期选择器不可清除
      totalWord: ['taxAllPrice', 'cost', 'profit', 'profitRate'], // 合计导出字段
      // tableKey: 1,
      total: 1, // 数据一共有多少条
      mainId: 'uuid', // 表格行ID
      tableHeight: '0', // 表格高度
      bottomTaxAllPrice: 0, // 订单金额
      bottomCost: 0, // 利润
      bottomProfit: 0, // 利润率
      bottomProfitRate: 0, // 利润率
      tableData: [], // 导出表格数据
      tableData2: [], // 表格数据
      tableColumns: [], // 表格实际用的字段
      searchColumns: [], // 搜索区实际用的字段
      selections: [], // 表格当前页所选中的行
      selectionsAll: [], // 表格所有页选中的行
      defaultTableColumns: [// 表格常规字段（初始值）
        { prop: 'saleOrderCode', label: '销售订单号', minWidth: '150', isRegular: true },
        { prop: 'orderByName', label: '销售人员', canOrder: false, minWidth: '80', isRegular: true },
        { prop: 'taxAllPrice', label: '订单金额', canOrder: false, isTime: true, minWidth: this.SETTINGS.settings_decimalDigits_length, isRegular: true },
        { prop: 'formTypeName', label: '成本类型', canOrder: false, minWidth: '120', isRegular: true },
        { prop: 'formCode', label: '单据编号', canOrder: false, minWidth: '120', isRegular: true },
        { prop: 'cost', label: '成本', canOrder: false, minWidth: '120' },
        { prop: 'profit', label: '利润', canOrder: false, position: 'left', minWidth: '120' },
        { prop: 'profitRate', label: '利润率(%)', canOrder: false, position: 'left', minWidth: '120' }
      ],
      exportTableColumns: [
        { prop: 'saleOrderCode', label: '销售订单号', minWidth: '150' },
        { prop: 'orderByName', label: '销售人员', canOrder: false, minWidth: '80' },
        { prop: 'taxAllPrice', label: '订单金额', isTime: true, minWidth: this.SETTINGS.settings_decimalDigits_length },
        { prop: 'formTypeName', label: '成本类型', minWidth: '120' },
        { prop: 'formCode', label: '单据编号', canOrder: false, minWidth: '120' },
        { prop: 'cost', label: '成本', canOrder: false, minWidth: '120' },
        { prop: 'profit', label: '利润', canOrder: false, position: 'left', minWidth: '120' },
        { prop: 'profitRate', label: '利润率(%)', canOrder: false, position: 'left', minWidth: '120' }
      ],
      defaultExport: [],
      defaultSearchColumns: [// 搜索区常规字段（初始值）
        { prop: 'saleOrderCode', label: '销售订单号', type: 'input' },
        { prop: 'orderByName', label: '销售人员', type: 'input' },
        { prop: 'formType', label: '成本类型', type: 'select', optionsName: 'customer' },
        { prop: 'formCode', label: '单据编号', type: 'input' }
      ],
      operationData: [ // 右上角的操作按钮
        { label: '批量导出3', perm: '' },
        { label: '页面配置2', perm: '' }
      ],
      customer: [
        { value: undefined, label: '全部' },
        { value: '1', label: '采购' },
        { value: '2', label: '外协' },
        { value: '3', label: '人力' },
        { value: '4', label: '其他' }
      ],
      showKey: [
        {
          name: '基本信息',
          columns: [
            { type: 'form', name: '销售订单号', key: 'code' },
            { type: 'form', name: '制单人员', key: 'orderName' },
            { type: 'form', name: '制单日期', key: 'orderTime' },
            { type: 'form', name: '订单类型', key: 'orderTypeLabel' },
            { type: 'form', name: '客户名称', key: 'customerName' },
            { type: 'form', name: '订货日期', key: 'orderGoodsTime' },
            { type: 'form', name: '合同号', key: 'contractCode' },
            { type: 'form', name: '未税总金额', key: 'allPriceThousandths' },
            { type: 'form', name: '含税总金额', key: 'taxAllPriceThousandths' },
            { type: 'form', name: '税额', key: 'tax' },
            { type: 'file', name: '附件', fileName: 'fileName', fileRealName: 'fileRealName', fileUrl: 'url' },
            { type: 'form', name: '备注', key: 'remark', length: 'double' },
            {
              type: 'table', name: '', key: 'data'
            }
          ]
        },
        {
          name: '客户信息',
          columns: [
            // { type: 'formData', name: '计税方式', key: 'taxTypeLabel' },
            // { type: 'formData', name: '税率%', key: 'taxRateLabel' },
            // { type: 'formData', name: '结算方式', key: 'settlementTypeLabel' },
            // { type: 'formData', name: '结算币别', key: 'settlementCurrencyLabel' },
            { type: 'formData2', name: '交货方式', key: 'deliveryTypeLabel' },
            { type: 'formData2', name: '联系人', key: 'consignee' },
            { type: 'formData2', name: '联系方式', key: 'phone' },
            { type: 'formData2', name: '注意事项', key: 'attentionMatters' },
            { type: 'formData2', name: '收货地址', key: 'deliveryAddress', length: 'double' }
          ]
        },
        {
          name: '审批详情',
          columns: [
            { type: 'review', name: '评审进度', key: 'taskList' }
          ]
        }
      ],
      showKey1: {
        type: 'column_two',
        name: '基本信息',
        keys: [
          { type: 'form', name: '采购订单号', key: 'code' }, // type: 'form' 表示是普通的表单展示
          { type: 'form', name: '采购人员', key: 'orderName' },
          { type: 'form', name: '采购日期', key: 'orderTime' },
          { type: 'form', name: '供应商名称', key: 'supplierName' },
          { type: 'form', name: '总数量', key: 'totalNumber' }, // length:'double' 表示占两列
          { type: 'form', name: '含税总金额', key: 'taxTotalMoneyThousandths' },
          { type: 'file', name: '附件', fileName: 'fileName', fileRealName: 'fileRealName', fileUrl: 'url' },
          { type: 'form', name: '备注', key: 'remark', length: 'double' },
          {
            type: 'table', name: '', key: 'detailList', columns: [ // type: 'table' 表示是表格// type: 'form' 表示是普通的表单展示
              { type: 'column', name: '物料编码', key: 'materialCode', minWidth: '120' }, // type: 'form' 表示是普通的表单展示
              { type: 'column', name: '物料名称', key: 'materialName', minWidth: '100' },
              { type: 'column', name: '规格型号', key: 'materialModel', minWidth: '100' },
              { type: 'column', name: '物料单位', key: 'materialUnitLabel', minWidth: '100' },
              { type: 'column', name: '采购数量', key: 'purchaseNumber', minWidth: this.SETTINGS.settings_decimalDigits_length, fixed: 'right' },
              { type: 'column', name: '含税单价', key: 'taxPriceThousandths', minWidth: this.SETTINGS.settings_decimalDigits_length, align: 'right' }, // type: 'form' 表示是普通的表单展示
              { type: 'column', name: '税率%', key: 'taxRateCode', minWidth: '100' },
              { type: 'column', name: '含税总金额', key: 'totalTaxPriceThousandths', minWidth: this.SETTINGS.settings_decimalDigits_length, align: 'right' },
              { type: 'column', name: '采购交期', key: 'purchaseDeliveryTime', minWidth: '140' },
              { type: 'column', name: '备注', key: 'remark', minWidth: '200' }
            ]
          }
        ]
      },
      showKey2: {
        type: 'column_two',
        keys: [
          { type: 'form', name: '外协订单号', key: 'code' }, // type: 'form' 表示是普通的表单展示
          { type: 'form', name: '制单人员', key: 'orderName' },
          { type: 'form', name: '制单日期', key: 'orderTime' },
          // { type: 'form', name: '外协类型', key: 'supplierTypeName' },
          { type: 'form', name: '计划单号', key: 'productionPlanCode' },
          { type: 'form', name: '外协供应商', key: 'supplierName' },
          { type: 'form', name: '外协总数量', key: 'totalNumber' }, // length:'double' 表示占两列
          { type: 'form', name: '含税总金额', key: 'taxTotalMoneyThousandths' },
          { type: 'file', name: '附件', fileName: 'fileName', fileRealName: 'fileRealName', fileUrl: 'url' },
          { type: 'form', name: '备注', key: 'remark', length: 'double' },
          {
            type: 'table',
            name: '',
            key: 'detailList',
            columns: [
              // type: 'table' 表示是表格
              {
                type: 'column',
                name: '工艺要求',
                fixed: 'right',
                key: 'engineeringRequirementCode',
                minWidth: '140'
              },
              {
                type: 'column',
                name: '工序',
                fixed: 'right',
                key: 'engineeringProcessName',
                minWidth: '80'
              },
              {
                type: 'column',
                name: '外协数量',
                fixed: 'right',
                key: 'outsourceNumber',
                minWidth: this.SETTINGS.settings_decimalDigits_length
              },
              {
                type: 'column',
                name: '物料编码',
                key: 'materialCode',
                minWidth: '120'
              }, // type: 'form' 表示是普通的表单展示
              {
                type: 'column',
                name: '物料名称',
                key: 'materialName',
                minWidth: '100'
              },
              {
                type: 'column',
                name: '规格型号',
                key: 'materialModel',
                minWidth: '100'
              },
              {
                type: 'column',
                name: '物料单位',
                key: 'materialUnitName',
                minWidth: '100'
              },
              {
                type: 'column',
                name: '需求数量',
                key: 'needNumber',
                minWidth: this.SETTINGS.settings_decimalDigits_length
              },
              {
                type: 'column',
                name: '含税单价',
                key: 'taxPriceThousandths',
                align: 'right',
                minWidth: '100'
              }, // type: 'form' 表示是普通的表单展示
              {
                type: 'column',
                name: '税率%',
                key: 'taxRateLabel',
                minWidth: this.SETTINGS.settings_decimalDigits_length
              },
              {
                type: 'column',
                name: '含税总金额',
                key: 'totalTaxPrice',
                minWidth: this.SETTINGS.settings_decimalDigits_length
              },
              {
                type: 'column',
                name: '外协交期',
                key: 'outsourceDeliveryTime',
                minWidth: '140'
              },
              { type: 'column', name: '备注', key: 'remark', minWidth: '200' }
            ]
          },
          {
            type: 'table2',
            name: '',
            key: 'scheduleList',
            columns: [
              // type: 'table' 表示是表格
              {
                type: 'column',
                name: '物料编码',
                key: 'materialCode',
                minWidth: '120'
              },
              {
                type: 'column',
                name: '物料名称',
                key: 'materialName',
                minWidth: '100'
              },
              {
                type: 'column',
                name: '工序',
                key: 'engineeringProcessName',
                minWidth: '100'
              },
              {
                type: 'column',
                name: '外协数量',
                key: 'outsourceNumber',
                minWidth: this.SETTINGS.settings_decimalDigits_length
              },
              // {
              //   type: 'column',
              //   name: '已领原料',
              //   key: 'hasRequisitionNumber',
              //   minWidth: this.SETTINGS.settings_decimalDigits_length
              // },
              // {
              //   type: 'column',
              //   name: '已退原料',
              //   key: 'returnNumber',
              //   minWidth: this.SETTINGS.settings_decimalDigits_length
              // }, // type: 'form' 表示是普通的表单展示
              {
                type: 'column',
                name: '完成数量',
                key: 'hasInspectNumber',
                minWidth: this.SETTINGS.settings_decimalDigits_length
              },
              {
                type: 'column',
                name: '合格数量',
                key: 'qualifiedNumber',
                minWidth: this.SETTINGS.settings_decimalDigits_length
              },
              {
                type: 'column',
                name: '不合格数',
                key: 'qualityDisqualificationDisposeNumber',
                minWidth: this.SETTINGS.settings_decimalDigits_length
              },
              {
                type: 'column',
                name: '进度',
                key: 'schedule',
                minWidth: '100'
              }
            ]
          }
        ]
      },
      // 自动流转查看详情的配置（根据配置自动生成查看页面）
      showKey3: {
        type: 'column_two',
        keys: [
          { type: 'form', name: '外协订单号', key: 'code' }, // type: 'form' 表示是普通的表单展示
          { type: 'form', name: '制单人员', key: 'orderName' },
          { type: 'form', name: '制单日期', key: 'orderTime' },
          // { type: 'form', name: '外协类型', key: 'supplierTypeName' },
          { type: 'form', name: '计划单号', key: 'productionPlanCode' },
          { type: 'form', name: '外协供应商', key: 'supplierName' },
          { type: 'form', name: '外协总数量', key: 'totalNumber' }, // length:'double' 表示占两列
          { type: 'form', name: '含税总金额', key: 'taxTotalMoneyThousandths' },
          { type: 'file', name: '附件', fileName: 'fileName', fileRealName: 'fileRealName', fileUrl: 'url' },
          { type: 'form', name: '备注', key: 'remark', length: 'double' },
          {
            type: 'table',
            name: '',
            key: 'detailList',
            columns: [
              // type: 'table' 表示是表格
              {
                type: 'column',
                name: '工艺要求',
                fixed: 'right',
                key: 'engineeringRequirementVersionCode',
                minWidth: '140'
              },
              {
                type: 'column',
                name: '工序',
                fixed: 'right',
                key: 'engineeringProcessName',
                minWidth: '80'
              },
              {
                type: 'column',
                name: '外协数量',
                fixed: 'right',
                key: 'outsourceNumber',
                minWidth: this.SETTINGS.settings_decimalDigits_length
              },
              {
                type: 'column',
                name: '物料编码',
                key: 'materialCode',
                minWidth: '120'
              }, // type: 'form' 表示是普通的表单展示
              {
                type: 'column',
                name: '物料名称',
                key: 'materialName',
                minWidth: '100'
              },
              {
                type: 'column',
                name: '规格型号',
                key: 'materialModel',
                minWidth: '100'
              },
              {
                type: 'column',
                name: '物料单位',
                key: 'materialUnitName',
                minWidth: '100'
              },
              {
                type: 'column',
                name: '需求数量',
                key: 'needNumber',
                minWidth: this.SETTINGS.settings_decimalDigits_length
              },
              {
                type: 'column',
                name: '含税单价',
                key: 'taxPriceThousandths',
                align: 'right',
                minWidth: '100'
              }, // type: 'form' 表示是普通的表单展示
              {
                type: 'column',
                name: '税率%',
                key: 'taxRateLabel',
                minWidth: this.SETTINGS.settings_decimalDigits_length
              },
              {
                type: 'column',
                name: '含税总金额',
                key: 'totalTaxPrice',
                minWidth: this.SETTINGS.settings_decimalDigits_length
              },
              {
                type: 'column',
                name: '外协交期',
                key: 'outsourceDeliveryTime',
                minWidth: '140'
              },
              { type: 'column', name: '备注', key: 'remark', minWidth: '200' }
            ]
          },
          {
            type: 'table2',
            name: '',
            key: 'scheduleList',
            columns: [
              // type: 'table' 表示是表格
              { type: 'column', name: '任务单号', key: 'productionTaskCode', minWidth: '120' }, // type: 'form' 表示是普通的表单展示
              {
                type: 'column',
                name: '物料编码',
                key: 'materialCode',
                minWidth: '120'
              },
              {
                type: 'column',
                name: '物料名称',
                key: 'materialName',
                minWidth: '100'
              },
              {
                type: 'column',
                name: '工序',
                key: 'engineeringProcessName',
                minWidth: '100'
              },
              {
                type: 'column',
                name: '外协数量',
                key: 'outsourceNumber',
                minWidth: this.SETTINGS.settings_decimalDigits_length
              },
              {
                type: 'column',
                name: '已领原料',
                key: 'hasRequisitionNumber',
                minWidth: this.SETTINGS.settings_decimalDigits_length
              },
              {
                type: 'column',
                name: '已退原料',
                key: 'returnNumber',
                minWidth: this.SETTINGS.settings_decimalDigits_length
              }, // type: 'form' 表示是普通的表单展示
              {
                type: 'column',
                name: '完成数量',
                key: 'hasInspectNumber',
                minWidth: this.SETTINGS.settings_decimalDigits_length
              },
              {
                type: 'column',
                name: '合格数量',
                key: 'qualifiedNumber',
                minWidth: this.SETTINGS.settings_decimalDigits_length
              },
              {
                type: 'column',
                name: '不合格数',
                key: 'qualityDisqualificationDisposeNumber',
                minWidth: this.SETTINGS.settings_decimalDigits_length
              },
              {
                type: 'column',
                name: '进度',
                key: 'schedule',
                minWidth: '100'
              }
            ]
          }
        ]
      },
      showKey4: { // 查看详情的配置（根据配置自动生成查看页面）
        type: 'column_two',
        keys: [
          { type: 'form', name: '计划单号', key: 'code' }, // type: 'form' 表示是普通的表单展示
          { type: 'form', name: '销售订单', key: 'saleOrderCode' },
          { type: 'form', name: '计划类型', key: 'planTypeLabel' },
          { type: 'form', name: '计划人员', key: 'planPersonName' },
          { type: 'form', name: '计划日期', key: 'planTime' }, // length:'double' 表示占两列
          { type: 'Invoices', name: '生产任务单', key: 'enterWarehouseInvoices', length: 'double' },
          { type: 'form', name: '生产模式', key: 'modelName', length: 'double' },
          { type: 'form', name: '备注', key: 'remark', length: 'double' },
          {
            type: 'table', name: '物料明细', key: 'unmergeData', columns: [ // type: 'table' 表示是表格
              { type: 'column', name: '物料编码', key: 'materialCode', minWidth: '140' }, // type: 'form' 表示是普通的表单展示
              { type: 'column', name: '物料名称', key: 'materialName', minWidth: '100' },
              { type: 'column', name: '规格型号', key: 'materialModel', minWidth: '100' },
              { type: 'column', name: '物料分类', key: 'materialTypeName', minWidth: '100' },
              { type: 'column', name: '物料单位', key: 'materialUnitName', minWidth: '80' },
              { type: 'column', name: '工艺版本号', key: 'engineeringRequirementVersionCode', minWidth: '100' },
              { type: 'column', name: '客户交期', key: 'saleCustomerDeliveryTime', minWidth: '110' },
              { type: 'column', name: '订单数量', key: 'orderNumber', minWidth: '100' },
              { type: 'column', name: '库存数量', key: 'materialInventory', minWidth: '100' },
              { type: 'column', name: '计划数量', fixed: 'right', key: 'planNumber', Width: this.SETTINGS.settings_decimalDigits_length },
              { type: 'column', name: '计划交期', key: 'planDealTime', minWidth: '110' },
              { type: 'column', name: '备注', key: 'remark', minWidth: '120' }
            ]
          },
          {
            type: 'table', name: '', key: 'productionTaskListVos', columns: [ // type: 'table' 表示是表格
              { type: 'column', name: '任务单号', key: 'code', minWidth: '120' }, // type: 'form' 表示是普通的表单展示
              { type: 'column', name: '任务类型', key: 'taskTypeName', minWidth: '100' }, // type: 'form' 表示是普通的表单展示

              { type: 'column', name: '物料编码', key: 'materialCode', minWidth: '120' },
              { type: 'column', name: '物料名称', key: 'materialName', minWidth: '100' },
              { type: 'column', name: '规格型号', key: 'materialModel', minWidth: '100' },
              { type: 'column', name: '工序', key: 'engineeringProcessName', minWidth: '100' },
              { type: 'column', name: '是否外协', key: 'productBySelfName', minWidth: '80' },
              { type: 'column', name: '计划数量', key: 'productNumber', Width: this.SETTINGS.settings_decimalDigits_length },
              { type: 'column', name: '完成数量', key: 'finishNumber', Width: this.SETTINGS.settings_decimalDigits_length },
              { type: 'column', name: '合格数量', key: 'qualifiedTotalNumber', Width: this.SETTINGS.settings_decimalDigits_length },
              { type: 'column', name: '不合格数量', key: 'unqualifiedNumber', Width: this.SETTINGS.settings_decimalDigits_length },
              { type: 'column', name: '进度', key: 'rateOfProgress', minWidth: '80' },
              { type: 'operate', name: '操作', key: 'schedule', minWidth: '60' }

            ]
          }
        ]
      },
      showKey5: { // 查看详情的配置（根据配置自动生成查看页面）
        type: 'column_two',
        keys: [
          { type: 'form', name: '计划单号', key: 'code' }, // type: 'form' 表示是普通的表单展示
          { type: 'form', name: '销售订单', key: 'saleOrderCode' },
          { type: 'form', name: '计划类型', key: 'planTypeLabel' },
          { type: 'form', name: '计划人员', key: 'planPersonName' },
          { type: 'form', name: '计划日期', key: 'planTime' }, // length:'double' 表示占两列
          { type: 'Invoices', name: '生产任务单', key: 'enterWarehouseInvoices', length: 'double' },
          { type: 'form', name: '生产模式', key: 'modelName', length: 'double' },
          { type: 'form', name: '备注', key: 'remark', length: 'double' },
          {
            type: 'table', name: '物料明细', key: 'unmergeData', columns: [ // type: 'table' 表示是表格
              { type: 'column', name: '物料编码', key: 'materialCode', minWidth: '140' }, // type: 'form' 表示是普通的表单展示
              { type: 'column', name: '物料名称', key: 'materialName', minWidth: '100' },
              { type: 'column', name: '规格型号', key: 'materialModel', minWidth: '100' },
              { type: 'column', name: '物料分类', key: 'materialTypeName', minWidth: '100' },
              { type: 'column', name: '物料单位', key: 'materialUnitName', minWidth: '80' },
              { type: 'column', name: 'BOM版本号', key: 'engineeringBomVersion', minWidth: '100' },
              { type: 'column', name: '工艺路线', key: 'engineeringPathCode', minWidth: '120' },
              { type: 'column', name: '工艺路线版本号', key: 'engineeringPathVersion', minWidth: '120' },
              { type: 'column', name: '客户交期', key: 'saleCustomerDeliveryTime', minWidth: '110' },
              { type: 'column', name: '订单数量', key: 'orderNumber', minWidth: '100' },
              { type: 'column', name: '库存数量', key: 'materialInventory', minWidth: '100' },
              { type: 'column', name: '计划数量', fixed: 'right', key: 'planNumber', Width: this.SETTINGS.settings_decimalDigits_length },
              { type: 'column', name: '计划交期', key: 'planDealTime', minWidth: '110' },
              { type: 'column', name: '备注', key: 'remark', minWidth: '120' }
            ]
          },
          {
            type: 'table', name: '', key: 'productionTaskListVos', columns: [ // type: 'table' 表示是表格
              { type: 'column', name: '任务单号', key: 'code', minWidth: '120' }, // type: 'form' 表示是普通的表单展示
              { type: 'column', name: '任务类型', key: 'taskTypeName', minWidth: '100' }, // type: 'form' 表示是普通的表单展示

              { type: 'column', name: '物料编码', key: 'materialCode', minWidth: '120' },
              { type: 'column', name: '物料名称', key: 'materialName', minWidth: '100' },
              { type: 'column', name: '规格型号', key: 'materialModel', minWidth: '100' },
              { type: 'column', name: '工序', key: 'engineeringProcessName', minWidth: '100' },
              { type: 'column', name: '是否外协', key: 'productBySelfName', minWidth: '80' },
              { type: 'column', name: '计划数量', key: 'productNumber', Width: this.SETTINGS.settings_decimalDigits_length },
              { type: 'column', name: '完成数量', key: 'finishNumber', Width: this.SETTINGS.settings_decimalDigits_length },
              { type: 'column', name: '合格数量', key: 'qualifiedTotalNumber', Width: this.SETTINGS.settings_decimalDigits_length },
              { type: 'column', name: '不合格数量', key: 'unqualifiedNumber', Width: this.SETTINGS.settings_decimalDigits_length },
              { type: 'column', name: '进度', key: 'rateOfProgress', minWidth: '80' },
              { type: 'operate', name: '操作', key: 'schedule', minWidth: '60' }

            ]
          }
        ]
      },
      showKey6: [
        {
          name: '基本信息',
          columns: [
            { type: 'form', name: '付款单号', key: 'code' },
            { type: 'form', name: '制单人员', key: 'receiptByName' },
            { type: 'form', name: '制单日期', key: 'receiptTime' },
            { type: 'form', name: '付款方', key: 'payer' },
            { type: 'form', name: '付款类型', key: 'paymentTypeCodeName' },
            { type: 'form', name: '关联订单', key: 'formCode' },
            { type: 'form', name: '含税总金额', key: 'taxAllPrice' },
            { type: 'file1', name: '订单附件', fileName: 'orderFileName', fileRealName: 'orderFileRealName', fileUrl: 'orderUrl' },
            { type: 'file', name: '附件', fileName: 'fileName', fileRealName: 'fileRealName', fileUrl: 'fileUrl' },
            { type: 'form', name: '备注', key: 'remark', length: 'double' },
            {
              type: 'table', name: '', key: 'details'
            }
          ]
        },
        {
          name: '供应商收款信息',
          columns: [
            {
              type: 'table2', name: '', key: 'concatSupplierList', columns: [ // type: 'table' 表示是表格
                { name: '银行账号', key: 'bankAccount' },
                { name: '账户名称', key: 'accountName' },
                { name: '收款银行', key: 'dueBank' },
                { name: '注意事项', key: 'announcements' }
              ]
            }
          ]
        },
        {
          name: '审批详情',
          columns: [
            { type: 'review', name: '评审进度', key: 'taskList' }
          ]
        }
      ]
    }
  },
  watch: {
    tableData() {
      this.$nextTick(() => {
        for (const elementNodeListOfElement of document.querySelectorAll('.SaleOrderCodeColumnClass')) {
          if (!elementNodeListOfElement.childNodes[0].childNodes[0].className || elementNodeListOfElement.childNodes[0].childNodes[0].className == 'commonTableColumn') {
            const paddingNode = document.createElement('div')
            paddingNode.className = 'SaleOrderCodeColumnClass_expand'
            paddingNode.innerHTML = ''
            elementNodeListOfElement.childNodes[0].insertBefore(paddingNode, elementNodeListOfElement.childNodes[0].childNodes[0])
          }
        }
      })
    }
  },
  created() {
    // // 获取当前日期
    // this.returnTimeDefaul = [this.$moment().startOf('month').format('YYYY-MM-DD') + ' 00:00',
    //   this.$moment(new Date()).format('YYYY-MM-DD') + ' 23:59']
  },
  mounted() {
    // this.getDictSelects()
  },
  methods: {
    cellClassName({ row, column, rowIndex, columnIndex }) {
      if (columnIndex == 1) {
        return 'SaleOrderCodeColumnClass'
      }
      if (!row.isNotselected) {
        return 'displayNoneClass'
      }
    },
    cellStyle({ row, column }) {
      if (column.property == 'formCode') {
        return {
          cursor: 'pointer',
          color: '#387bfc'
        }
      }
      if (column.property == 'saleOrderCode') {
        return {
          cursor: 'pointer',
          color: '#387bfc'
        }
      }
    },
    cellClick(row, column, cell) {
      if (row.formCode) {
        switch (column.property) {
          case 'formCode':
            this.showDetail(row)
            break
        }
      }
      if (row.saleOrderCode) {
        switch (column.property) {
          case 'saleOrderCode':
            this.showDetailSale(row)
            break
        }
      }
    },
    showDetailSale(row) {
      getInfo(row.saleOrderId).then(res => {
        this.$layer.iframe({// 弹框
          content: {
            content: showDetailSale, // 传递的组件对象
            parent: this, // 当前的vue对象
            data: {
              businessId: row.saleOrderId,
              showData: res.data,
              showKey: this.showKey
            }// props
          },
          area: ['1320px', '700px'],
          title: '查看销售订单', // 标题
          shadeClose: false // 点击遮罩是否关闭
        })
      })
      this.$store.dispatch('notification/changeId', 0)
    },
    showDetail(row) {
      if (row.formTypeName == '采购') {
        productionInfo(row.formId).then(res => {
          this.$layer.iframe({// 弹框
            content: {
              content: ShowPurchaseDetail, // 传递的组件对象
              parent: this, // 当前的vue对象
              data: {
                showData: res.data,
                showKey: this.showKey1
              }// props
            },
            area: ['1430px', '700px'],
            title: '查看采购订单', // 标题
            shadeClose: false // 点击遮罩是否关闭
          })
        })
      } else if (row.formTypeName == '外协') {
        getOutsourceOrderInfo(row.formId).then((res) => {
          if (res.data.scheduleList && res.data.scheduleList.length > 0) {
            res.data.scheduleList.forEach(ele => {
              ele.schedule = parseFloat((ele.qualifiedNumber * 100 / ele.outsourceNumber).toFixed(2)) + '%'
            })
          }
          this.$layer.iframe({
            // 弹框
            content: {
              content: outsourceShowDetail, // 传递的组件对象
              parent: this, // 当前的vue对象
              data: {
                showData: res.data,
                showKey: res.data.automaticCreate == 1 ? this.showKey3 : this.showKey2
              } // props
            },
            area: ['1320px', '700px'],
            title: '查看外协订单', // 标题
            shadeClose: false // 点击遮罩是否关闭
          })
        })
      } else if (row.formTypeName == '人力') {
        let showKey = this.showKey4
        planProductionInfo(row.formId).then(res => {
          res.data.unmergeData = this.sumArr(res.data.unmergeData)
          // 计算合格数量
          res.data.productionTaskListVos.map((item) => {
            item.finishNumber = item.reportTotalNumber * 1 + item.badnessTotalNumber * 1
            item.unqualifiedNumber = item.disqualifiedTotalNumber * 1 + item.badnessTotalNumber * 1
            item.schedule = parseFloat((item.qualifiedTotalNumber * 100 / item.productNumber).toFixed(2)) + '%'
          })
          res.data.modelName = res.data.model == '1' ? '按BOM和工艺路线' : '按工艺要求'

          if (res.data.model == '1') {
            showKey = this.showKey5
          }
          this.$layer.iframe({// 弹框
            content: {
              content: ShowPlanProducionDetail, // 传递的组件对象
              parent: this, // 当前的vue对象
              data: {
                showData: res.data,
                showKey: showKey
              }// props
            },
            area: ['9999px', '9999px'],
            title: '查看生产计划单', // 标题
            shadeClose: false // 点击遮罩是否关闭
          })
        })
      } else if (row.formTypeName == '其他') {
        AdditionalInfo(row.formId).then(res => {
          this.$layer.iframe({// 弹框
            content: {
              content: ShowAdditionalDetail, // 传递的组件对象
              parent: this, // 当前的vue对象
              data: {
                showData: res.data,
                businessId: row[this.mainId],
                showKey: this.showKey6,
                isSaleOrder: true
              }// props
            },
            area: ['1320px', '700px'],
            title: '查看附加付款单', // 标题
            shadeClose: false // 点击遮罩是否关闭
          })
        })
      }
    },
    // 合并数据展示
    sumArr(arrList) {
      const nameArr = [...new Set(arrList.map(i => i.materialId))]// 名称集合
      const list = []
      nameArr.forEach(v => {
        const filterlist = arrList.filter(a => v == a.materialId)
        list.push(filterlist)
      })
      const outArr = []
      list.forEach((item, index) => {
        // if (!this.formData.id) {
        //   if (item.length > 1) {
        //     var min = Math.min.apply(Math, item.map(o => o.saleCustomerDeliveryTimeNumber))
        //     item[0].saleCustomerDeliveryTime = new Date(min).toLocaleDateString().slice().replace(/\//g, '-')
        //   }
        //   item[0].planDealTime = item[0].saleCustomerDeliveryTime
        // }
        // 新增第一次合并计算未发数量，否则计算计划数量
        // if (this.fristFalg) {
        //   // 合计订单数量
        //   const orderNumber = item.reduce((total, g) => {
        //     return total + Number(g.orderNumber)
        //   }, 0)
        //   const planNumber = item.reduce((total, g) => {
        //     return total + Number(g.willDeliverNumber)
        //   }, 0)
        //   outArr.push({
        //     ...item[0],
        //     orderNumber: orderNumber,
        //     planNumber: planNumber
        //   })
        // } else {
        // 合计订单数量
        const orderNumber = item.reduce((total, g) => {
          return total + Number(g.orderNumber)
        }, 0)
        const planNumber = item.reduce((total, g) => {
          return total + Number(g.planNumber)
        }, 0)
        // 如果订单数量合计为0则置空
        if (orderNumber == 0) {
          outArr.push({
            ...item[0],
            orderNumber: '',
            planNumber: planNumber
          })
        } else {
          outArr.push({
            ...item[0],
            orderNumber: orderNumber,
            planNumber: planNumber
          })
        }
        // }
      })
      return outArr
    },
    getList() {
      list(this.pageData).then(res => {
        res.data.data.forEach((item) => { item.isNotselected = true })
        this.tableData = res.data.data
        this.bottomTaxAllPrice = res.bottomTaxAllPrice // 订单金额
        this.bottomCost = res.bottomCost // 利润
        this.bottomProfit = res.bottomProfit // 利润率
        this.bottomProfitRate = res.bottomProfitRate // 利润率
        this.total = res.data.total
        // this.Updata = res.data
        this.loading = false
        this.$nextTick(() => {
          this.setSelectRow(this)// 设置行选中
          this.tableHeight = this.$refs.table_container.offsetHeight
          this.$refs.table.doLayout()
        })
      })
    },
    // 导出
    getExportData(data) {
      return new Promise(function(resolve, reject) {
        exporOrderProfittList(data).then(res => {
          resolve({ data: res.data.data, bottomTaxAllPrice: res.bottomTaxAllPrice, bottomCost: res.bottomCost, bottomProfit: res.bottomProfit, bottomProfitRate: res.bottomProfitRate })
        })
      })
    },
    // 合计行
    getSummaries(param) {
      const {
        columns
      } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index == 0) {
          sums[index] = '合计'
          return
        }
        switch (column.property) {
          case 'taxAllPrice':
            sums[index] = this.bottomTaxAllPrice
            break
        }
        switch (column.property) {
          case 'cost':
            sums[index] = this.bottomCost
            break
        }
        switch (column.property) {
          case 'profit':
            sums[index] = this.bottomProfit
            break
        }
        switch (column.property) {
          case 'profitRate':
            sums[index] = this.bottomProfitRate
            break
        }
      })
      return sums
    }
  }
}
</script>

<style lang="less" scoped>
/deep/.el-tooltip{
  display: flex;
}
/deep/ .el-table__footer-wrapper tbody td.el-table__cell{
  background-color: rgba(0,0,0,0);
}
/deep/ .el-table__footer-wrapper tbody td.el-table__cell{
  background-color: transparent!important;
}
/deep/ .el-table th.el-table__cell.is-leaf, .el-table td.el-table__cell {
  border-bottom: 1px solid #dfe6ec;
}

/deep/.el-table th.el-table__cell>.cell{
  padding-right: 15%;
}
/deep/.el-table .cell{
  padding-right: 15%;
}
/deep/ .SaleOrderCodeColumnClass_expand{
  display: inline-block;
  width: 20px;
  line-height: 20px;
  height: 20px;
  text-align: center;
  margin-right: 3px;
}
/deep/.el-table .displayNoneClass .cell .el-checkbox__inner{
  display: none
}
</style>
